home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Macintosh Drag and Drop / Demo Applications / FinderDrag / StringLib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-09  |  1.9 KB  |  65 lines  |  [TEXT/MPS ]

  1.  
  2. #include <Memory.h>
  3. #include "StringLib.h"
  4.  
  5.  
  6. //----------------------------------------------------------------------------
  7. // pstrcat
  8. //----------------------------------------------------------------------------
  9. void pstrcat(Str255 frontStr, ConstStr255Param backStr)
  10. {
  11.                                 // Limit combined string to 255 chars
  12.     short    backLength = backStr[0];
  13.     if (frontStr[0] + backLength > 255)
  14.         backLength = 255 - frontStr[0];
  15.  
  16.                                 // Copy second to end of first string
  17.     BlockMoveData(backStr + 1,  frontStr + frontStr[0] + 1, backLength);
  18.                                 // Set length of combined string
  19.     frontStr[0] += backLength;
  20.     
  21. }
  22.  
  23.  
  24. //----------------------------------------------------------------------------
  25. // newline
  26. //----------------------------------------------------------------------------
  27. void newline(Str255 str)
  28. {
  29.     Str32 newLine = "\p ";
  30.     newLine[1] = 0xD;
  31.  
  32.     pstrcat(str, newLine);
  33. }
  34.  
  35.  
  36. //----------------------------------------------------------------------------
  37. // pstrcpy
  38. //----------------------------------------------------------------------------
  39. void pstrcpy(void *src, void *dest)
  40. {
  41.     BlockMoveData(src, dest,(*(Str255 *)src)[0] + 1);
  42. }
  43.  
  44.  
  45. //----------------------------------------------------------------------------
  46. //    concat
  47. //
  48. //    The concat function takes a sequence of Pascal strings and concatenates
  49. //    them. The concatenated string is returned in resultString. The number of
  50. //    strings to concatenate is passed in stringCount.  Any practical number of
  51. //    ConstStr255Param parameters may be passed after the stringCount parameter.
  52. //----------------------------------------------------------------------------
  53. void concat(Str255 resultString, short stringCount, ...)
  54. {
  55.     va_list        currentString;
  56.     Str255        tempString = "\p";
  57.     
  58.     va_start(currentString, stringCount); /* point to first string variable */
  59.     while (stringCount--)
  60.         pstrcat(tempString, (StringPtr)va_arg(currentString, ConstStr255Param));
  61.     va_end(currentString);
  62.     pstrcpy(tempString, resultString);
  63.     return;
  64. }
  65.